import {createApp} from "vue";
import GaBindDialog from './GaBindDialog.vue';
import GaCaptchaDialog from './GaCaptchaDialog.vue';
import MailCaptchaDialog from './MailCaptchaDialog.vue';
import SmsCaptchaDialog from './SmsCaptchaDialog.vue';

import installElementPlus from "@/plugins/element";

export default function install() {
    // 挂载 GaBindDialog 组件
    mountComponent(GaBindDialog, 'gaBindDialog');

    // 挂载 GaCaptchaDialog 组件
    mountComponent(GaCaptchaDialog, 'gaCaptchaDialog');

    // 挂载 MailCaptchaDialog 组件
    mountComponent(MailCaptchaDialog, 'mailCaptchaDialog');

    // 挂载 SmsCaptchaDialog 组件
    mountComponent(SmsCaptchaDialog, 'smsCaptchaDialog');
}

// 创建并配置 Vue 应用实例的通用逻辑
const createComponentInstance = function (component) {
    const app = createApp(component);
    app.use(installElementPlus);
    return app;
}

// 通用挂载函数
function mountComponent(Component, globalName) {
    const container = document.createElement('div');
    document.body.appendChild(container);

    const app = createComponentInstance(Component);
    const instance = app.mount(container);

    // 可选：将组件实例挂载到 window 上，方便外部调用
    if (globalName && typeof globalName === 'string') {
        window[globalName] = instance;
    }

    return instance;
}
